/***********************************************************************
	filename: 	DaterServerSystem.cpp
	created:	9/5/2012
	author:		4Ys

	purpose:	Implementation of main server system object
*************************************************************************/

#include "DaterServerSystem.h"
#include "DaterOpCreater.h"
#include "DaterTransDefault.h"
#include "DaterTransEvent.h"
#include "DaterTransLogin.h"
#include "DaterTransSignUp.h"
#include "DaterTransGroup.h"
#include "DaterTransUser.h"
#include "DaterOfflineMessage.h"
#include "DaterRequestCenter.h"

namespace Dater
{
	//----------------------------------------------------------------------------//
	template<> ServerSystem* Singleton<ServerSystem>::ms_Singleton = 0;

	//----------------------------------------------------------------------------//
	ServerSystem& ServerSystem::create()
	{
		return *new ServerSystem;
	}

	//----------------------------------------------------------------------------//
	void ServerSystem::destory()
	{
		delete ServerSystem::getSingletonPtr();
	}

	//----------------------------------------------------------------------------//
	ServerSystem& ServerSystem::getSingleton()
	{
		return Singleton<ServerSystem>::getSingleton();
	}

	//----------------------------------------------------------------------------//
	ServerSystem* ServerSystem::getSingletonPtr(void)
	{
		return Singleton<ServerSystem>::getSingletonPtr();
	}

	//----------------------------------------------------------------------------//
	ServerSystem::ServerSystem()
	{
		createSingletons();
	}

	//----------------------------------------------------------------------------//
	ServerSystem::~ServerSystem()
	{
		destorySingletons();
	}

	//----------------------------------------------------------------------------//
	void ServerSystem::createSingletons()
	{
		new OfflineMessage();
		new RequestCenter();

		new TransDefault();
		new TransEventAdd();
		new TransEventUpdate();
		new TransEventDelete();
		new TransEventView();
		new TransLogin();
		new TransSignUp();
		new TransGroupCreate();
		new TransGroupAddMember();
		new TransGroupAskMember();
		new TransGroupView();
		new TransGroupJoin();
		new TransGroupAskJoin();
		new TransGroupPublishEvent();
		new TransGroupResponseToEvent();
		new TransGroupDeleteMember();
		new TransGroupList();
		new TransGroupSearch();
		new TransUserSearch();

		new OpCreater();
	}
	//----------------------------------------------------------------------------//

	void ServerSystem::destorySingletons()
	{
		delete OpCreater::getSingletonPtr();

		delete TransDefault::getSingletonPtr();
		delete TransEventAdd::getSingletonPtr();
		delete TransEventUpdate::getSingletonPtr();
		delete TransEventDelete::getSingletonPtr();
		delete TransEventView::getSingletonPtr();
		delete TransLogin::getSingletonPtr();
		delete TransSignUp::getSingletonPtr();
		delete TransGroupCreate::getSingletonPtr();
		delete TransGroupAddMember::getSingletonPtr();
		delete TransGroupAskMember::getSingletonPtr();
		delete TransGroupView::getSingletonPtr();
		delete TransGroupJoin::getSingletonPtr();
		delete TransGroupAskJoin::getSingletonPtr();
		delete TransGroupPublishEvent::getSingletonPtr();
		delete TransGroupResponseToEvent::getSingletonPtr();
		delete TransGroupDeleteMember::getSingletonPtr();
		delete TransGroupList::getSingletonPtr();
		delete TransGroupSearch::getSingletonPtr();
		delete TransUserSearch::getSingletonPtr();

		delete RequestCenter::getSingletonPtr();
		delete OfflineMessage::getSingletonPtr();
	}
}